import * as zrender from 'zrender';
import { barHeight } from '../../config';

// 排班条的纵向间距配置
const SCHEDULE_BAR_VERTICAL_PADDING = 3;
const SCHEDULE_BAR_HEIGHT = barHeight - (SCHEDULE_BAR_VERTICAL_PADDING * 2);

/**
 * 添加排班文字
 * @param group 排班条组
 * @param shift 排班对象
 * @param width 宽度
 */
export function addScheduleText(group: any, shift: Shift, width: number) {
  // 排班名称
  const nameText = new zrender.Text({
    style: {
      text: shift.name,
      x: 15,
      y: SCHEDULE_BAR_HEIGHT / 2 - 3,
      align: 'left',
      verticalAlign: 'middle',
      fontSize: 12,
      fontWeight: 'bold',
      fill: '#fff',
    },
    silent: true,
  });
  group.add(nameText);

  // 如果宽度足够，显示排班类型
  if (width > 100) {
    const typeText = new zrender.Text({
      style: {
        text: getShiftTypeLabel(shift.type),
        x: 15,
        y: SCHEDULE_BAR_HEIGHT / 2 + 8,
        align: 'left',
        verticalAlign: 'middle',
        fontSize: 10,
        fill: '#fff',
        opacity: 0.8,
      },
      silent: true,
    });
    group.add(typeText);
  }
}

/**
 * 获取排班类型标签
 * @param type 排班类型
 * @returns 类型标签
 */
export function getShiftTypeLabel(type: Shift['type']): string {
  const typeLabels = {
    morning: '早班',
    afternoon: '中班',
    night: '晚班',
    rest: '休息',
    overtime: '加班',
    meeting: '会议',
    training: '培训',
  };
  return typeLabels[type] || type;
}
